<?php
/** 初始化项目 */
require '../../app/app.php';
/** 初始化数据库 */
use app\util\Mysql;
$database = Mysql::init();


$username = $_SESSION['username'];
$out = array('code' => '0', "msg" => "", "count" => "", "data" => ""); //定义返回数组
// $limit = isset($_POST['limit']) ? intval($_POST['limit']) : 5;
// $page = isset($_POST['page']) ? intval($_POST['page']) : 1;
// $offset = $limit * ($page - 1);
$page = ($_POST["page"] - 1) * $_POST["limit"]; //数组以0起始
$limit = $_POST["limit"];
$list = $database->select("text_main", ["[>]text_auth" => "tid"], ["tid", "textname", "gread", "otherread", "created", "status"], ["creator" => $username, "LIMIT" => [$page, $limit]]);
$count = $database->count("text_main", ["[>]text_auth" => "tid"], ["tid"], ["creator" => $username]);

for ($i = count($list); $i > 0; $i--) {
    $time = $list[$i - 1]["created"];
    $times = new DateTime("@$time");
    $times->setTimezone(new DateTimeZone('Asia/Shanghai'));
    $times = $times->format('Y-m-d H:i:s');
    $list[$i - 1]["created"] = $times;
}
$out["count"] = $count;
$out["data"] = $list;
echo json_encode($out);
?>